package com.tengchao.books.controller;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.tengchao.books.exception.DataNotFoundException;
import com.tengchao.books.model.Book;
import com.tengchao.books.service.BookService;

@RestController
@RequestMapping("/bookstore")
public class BookController {

	private static final Logger LOGGER = Logger.getLogger(BookController.class);
	
	// bind with BookServiceImpl class
	@Autowired
	private BookService bookService;
	
	/**
	 * Get specific book details
	 * @param bookid
	 * @return book JSONObject
	 * @throws DataNotFoundException
	 */
	@RequestMapping(value = "/books/{bookid}", method = RequestMethod.GET)
	public @ResponseBody ResponseEntity<Book> getBook(@PathVariable int bookid)
			throws DataNotFoundException{
		
		LOGGER.info("GET PAYLOAD SUCCESSFULLY");
		Book book = null;
		
		book = bookService.getBook(bookid);
		
		return new ResponseEntity<Book>(book, HttpStatus.OK);
	}
}
